﻿var mtrList;//查询的会议室列表
var startTime;
var endTime;
var startDate;
var endDate;
var theme;
var weekdays = [];
var EngWeekdays = [];
var weeks = "";
var meetingRoomNo;
var mtrName;
var mtrNO;//会议室编号
var startTrSeq;
var startTdSeq;
var periodTime;
var tdWidth;
var tdHeight;
var dateChoose;
var bookingVIP;//预定的会议室是否是VIP会议室
var days = 5;//默认显示的天数
var userName;
var userType1;
var userType3;
var userLevel;
var EmailList;
var NameAndEmail;
var type;
var maxTd;
var minTd;

$(document).ready(function () {
    $("#isVIP").indeterminate = true;
    $("#manager").addClass("hidden");
    $("#lock").addClass("hidden");
    $("#cycleDiv").addClass("hidden");
    $("#manage_instanse").addClass("hidden");
    $("#datepicker").attr("value", new Date().Format("yyyy-MM-dd"));
    $("input[name=cycle]:eq(0)").attr("checked", 'checked');
    userName = $("#hidUserName").val();
    userType1 = $("#hidUserType1").val();
    userType3 = $("#hidUserType3").val();
    userLevel = $("#adminL").val();
    if (userName == null || userName == "") {
        location.href = "../Login.aspx";
        return;
    }
    if (userLevel >= 1) {
        $("#manager").removeClass("hidden");
        $("#lock").removeClass("hidden");
        $("#cycleDiv").removeClass("hidden");
        $("#manage_instanse").removeClass("hidden");
    }
    //$("bg").addClass("hidden");
    $("#weekdays_div").addClass("hidden");
    $("#fiveDaysAgo, #fiveDaysNext").addClass("hidden");

    $("#guide").click(function () {
        location.href = "../File/BookingSystemGuide.pptx";
    });

    $(".combobox").autocomplete("option", "disabled", true);

    var options1 = {
        type: "POST",
        url: "../Booking_chooseTime.asmx/getInstance",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: '{}',
        success: function (response) {
            if (response != null) {
                var instance = response.d;
                $("#booking_instanse").html(instance);
            }
        },
        error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
            alert('1'+result.responseText);
        }
    };
    $.ajax(options1);

    $("#tags").blur(function () {
        $("#checknames").click();
    })

    $("#checknames").click(function () {
        var strstart = $("#tags").val().split(";")[$("#tags").val().split(";").length - 1];
        if ($.trim(strstart) == null || $.trim(strstart) == "") {
            return;
        }
        var mat = StartWithByClick(NameAndEmail, $.trim(strstart));

        if (mat == "您输入的联系人系统中不存在") {
            alert("您输入的联系人系统中不存在");
        }
        else {
            $("#tags").html(rebuildContect($("#tags").val()) + mat);
        }
    })

    function rebuildContect(str)
    {
        var centect = new Array();
        var res ="" ;
        centect = str.split(";")
        for (var c = 0; c < centect.length - 1; c++) {
            res = res + centect[c] + "; ";
        }
        return res;
    }

    function StartWithByClick(availableTags, str) {
        str = str.toLowerCase();
        var match = new Array();
        var i = 0;
        for (var av = 0; av < availableTags.length; av++) {
            if (str == null || str == "" || availableTags[av].length == 0 || str.length > availableTags[av].length) {
                continue;
            }
            if (availableTags[av].substr(0, str.length) == str) {
                match[i] = availableTags[av];
                i++;
            }
        }
        if (match.length > 0) {
            return match[0].split(",")[match[0].split(",").length - 1].toLowerCase() + "; ";
        }
        if (match.length == 0) {
            return "您输入的联系人系统中不存在";
        }
    }
    //var options2 = {
    //    type: "POST",
    //    url: "../Booking_chooseTime.asmx/getEmails",
    //    dataType: "json",
    //    contentType: "application/json; charset=utf-8",
    //    data: '{}',
    //    success: function (response) {
    //        if (response != null) {
    //            EmailList=response.d;
    //            sk();
    //        }
    //    },
    //    error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
    //        alert(result.responseText);
    //    }
    //};
    //$.ajax(options2);

    var options3 = {
        type: "POST",
        url: "../Booking_chooseTime.asmx/getNameAndEmails",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: '{}',
        success: function (response) {
            if (response != null) {
                NameAndEmail = response.d;
                sk();
                sk1();
                sk2();
            }
        },
        error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
            alert('2' + result.responseText);
        }
    };
    $.ajax(options3);

    //邮箱
    function sk() {
        $(function () {
            if (NameAndEmail == null) {
            }
            var availableTags = NameAndEmail;
            function split(val) {
                return val.split(/;\s*/);
            }
            function extractLast(term) {
                return split(term).pop();
            }
            function StartWith(availableTags, str) {
                str = str.toLowerCase();
                var match = new Array();
                var i = 0;
                for (var av = 0; av < availableTags.length; av++) {
                    if (str == null || str == "" || availableTags[av].length == 0 || str.length > availableTags[av].length) {
                        continue;
                    }
                    if (availableTags[av].substr(0, str.length) == str) {
                        match[i] = availableTags[av];
                        i++;
                    }
                }
                return match;
            }
            $("#tags")
              .bind("keydown", function (event) {
                  if (event.keyCode === $.ui.keyCode.TAB &&
                      $(this).data("ui-autocomplete").menu.active) {
                      event.preventDefault();
                  }
              })
              .autocomplete({
                  minLength: 0,
                  autoFocus: true,
                  source: function (request, response) {
                      response(StartWith(availableTags, extractLast(request.term)));
                  },
                  focus: function () {
                      return false;
                  },
                  select: function (event, ui) {
                      var terms = split(this.value);
                      terms.pop();
                      //ui.item.value 
                      terms.push(ui.item.value.split(",")[ui.item.value.split(",").length - 1].toLowerCase());
                      terms.push("");
                      this.value = terms.join("; ");
                      //mailTran2(this.value);
                      goEnd();
                      return false;
                  }
              });
        });
    }
    //BOOK
    function sk1() {
        $(function () {
            if (NameAndEmail == null) {
            }
            var availableTags = NameAndEmail;
            function split(val) {
                return val.split(/;\s*/);
            }
            function extractLast(term) {
                return split(term).pop();
            }
            function StartWith(availableTags, str) {
                var match = new Array();
                var i = 0;
                for (var av = 0; av < availableTags.length; av++) {
                    if (str == null || str == "" || availableTags[av].length == 0 || str.length > availableTags[av].length) {
                        continue;
                    }
                    if (availableTags[av].substr(0, str.length) == str) {
                        match[i] = availableTags[av];
                        i++;
                    }
                }
                return match;
            }
            $("#nameAndEmail")
              .bind("keydown", function (event) {
                  if (event.keyCode === $.ui.keyCode.TAB &&
                      $(this).data("ui-autocomplete").menu.active) {
                      event.preventDefault();
                  }
              })
              .autocomplete({
                  minLength: 0,
                  autoFocus: true,
                  source: function (request, response) {
                      response(StartWith(availableTags, extractLast(request.term)));
                  },
                  focus: function () {
                      return false;
                  },
                  select: function (event, ui) {
                      var terms = split(this.value);
                      // remove the current input
                      terms.pop();
                      // add the selected item
                      terms.push(ui.item.value);
                      // add placeholder to get the comma-and-space at the end
                      terms.push("");
                      this.value = terms.join("; ");
                      mailTran1();
                      return false;
                  }
              });
        });
    }
    //CC
    function sk2() {  
        $(function () {
            if (NameAndEmail == null) {
            }
            var availableTags = NameAndEmail;
            function split(val) {
                return val.split(/;\s*/);
            }
            function extractLast(term) {
                return split(term).pop();
            }
            function StartWith(availableTags, str) {
                str = str.toLowerCase();
                var match = new Array();
                var i = 0;
                for (var av = 0; av < availableTags.length; av++) {
                    if (str == null || str == "" || availableTags[av].length == 0 || str.length > availableTags[av].length) {
                        continue;
                    }
                    if (availableTags[av].substr(0, str.length) == str) {
                        match[i] = availableTags[av];
                        i++;
                    }
                }
                return match;
            }
            $("#cc")
              .bind("keydown", function (event) {
                  if (event.keyCode === $.ui.keyCode.TAB &&
                      $(this).data("ui-autocomplete").menu.active) {
                      event.preventDefault();
                  }
              })
              .autocomplete({
                  minLength: 0,
                  autoFocus: true,
                  source: function (request, response) {
                      response(StartWith(availableTags, extractLast(request.term)));
                  },
                  focus: function () {
                      return false;
                  },
                  select: function (event, ui) {
                      var terms = split(this.value);
                      terms.pop();
                      //ui.item.value 
                      terms.push(ui.item.value.split(",")[ui.item.value.split(",").length - 1].toLowerCase());
                      terms.push("");
                      this.value = terms.join("; ");
                      //mailTran2(this.value);
                      goEnd1();
                      return false;
                  }
              });
        });
    }
   
    var options4 = {
        type: "POST",
        url: "../Booking_chooseTime.asmx/Init",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: '{}',
        success: function (response) {
            if (response != null) {
                initType(response.d);
                $("#seek").click();
                $("#seek").click();
            }
        },
        error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
            alert('3' + result.responseText);
        }
    };
    $.ajax(options4);

    function initType(tlist) {
        for (var tl = 0; tl < tlist.length; tl++) {
            $("#address").append("<option value = '" + tlist[tl] + "'>" + tlist[tl] + "</option>");
            if ($("#address").get(0).options[tl].text == "会议室") {
                $("#address").get(0).options[tl].selected = true;
            }
        }
    }

    function mailTran(value) {

        var notKnow = value.split(",")[value.split(",").length - 1];

        $("#tags").html($("#tags").val().split(";")[$("#tags").val().split(";").length - 1] + notKnow);
    }

    function mailTran1() {
        var notKnow = $("#nameAndEmail").val().split(",")[$("#nameAndEmail").val().split(",").length - 1];
        $("#tags").html($("#tags").val() + notKnow);
        $("#nameAndEmail").val("");   
    }
    function mailTran2(value) {
        var notKnow = value.split(",")[value.split(",").length - 1];
        $("#cc").html($("#cc").val().split(";")[$("#cc").val().split(";").length - 1] + notKnow);
       // $("#nameAndEmail").val("");
    }

    function goEnd1() {
        var isIE = CheckIE();  //判断是否是IE浏览器,方法略$("#tags");// 
        var obj = document.getElementById("cc");
        obj.scrollTop = obj.scrollHeight;
        if (isIE) {
            var txt = obj.createTextRange();
            txt.moveStart('character', obj.value.length);
            txt.collapse(true);
            txt.select();
        }
        else {
            obj.selectionStart = obj.value.length;
        }
    }

    function goEnd() {
        var isIE = CheckIE();  //判断是否是IE浏览器,方法略$("#tags");// 
        var obj = document.getElementById("tags");
        obj.scrollTop = obj.scrollHeight;
        if (isIE) {
            var txt = obj.createTextRange();
            txt.moveStart('character', obj.value.length);
            txt.collapse(true);
            txt.select();
        }
        else {
            obj.selectionStart = obj.value.length;
        }
    }
    function CheckIE() {
        if (/msie/i.test(navigator.userAgent)) {//ie浏览器
            return true;
        }
        else
            return false;
    }

    st("startTime");
    st("endTime");

    EngWeekdays = new Array(7);
    {
        EngWeekdays[0] = "Sunday"
        EngWeekdays[1] = "Monday"
        EngWeekdays[2] = "Tuesday"
        EngWeekdays[3] = "Wednesday"
        EngWeekdays[4] = "Thursday"
        EngWeekdays[5] = "Friday"
        EngWeekdays[6] = "Saturday"
    };


    function st(id_Text)
    {
        var ts = new Date();
        ts.setHours(8);
        ts.setMinutes(0);
        ts.setSeconds(0);
        do
        {
            var hou = ts.getHours() < 10 ? ("0" + ts.getHours()) : ts.getHours();
            var min = ts.getMinutes() == 0 ? (ts.getMinutes() + "0") : ts.getMinutes();
            var sva = ( hou + ":" + min.toString()).toString();
            $("#"+id_Text).append("<option value = '" + sva + "'>" + sva + "</option>");
            ts = ts.DateAdd('n', 10);
        }
        while (ts.getHours() < 17 || ts.getHours() == 17 && ts.getMinutes() < 31);
    }

    $("#meetingTheme").blur(function () {
        if ($("#meetingTheme").val() == null || $("#meetingTheme").val() == "") {
            alert("确定您发起的此次活动没有主题！");
        }
    })


    $("#fiveDaysNext").click(function () {
        if ($("#fiveDaysNext").val() == "后一天") {
            var ttst = getDate($("#datepicker").val()).DateAdd('d', 1).Format("yyyy-MM-dd");
            $("#datepicker").val(ttst);
        }
        else if ($("#fiveDaysNext").val() == "后五天") {
            var ttst = getDate($("#datepicker").val()).DateAdd('d', 5).Format("yyyy-MM-dd");
            $("#datepicker").val(ttst);
        }
        $("#seek").click();
    });
    $("#fiveDaysAgo").click(function () {
        if ($("#fiveDaysAgo").val() == "前一天") {
            var ttst = getDate($("#datepicker").val()).DateSub('d', 1).Format("yyyy-MM-dd");
            $("#datepicker").val(ttst);
        }
        else if ($("#fiveDaysAgo").val() == "前五天") {
            var ttst = getDate($("#datepicker").val()).DateSub('d', 5).Format("yyyy-MM-dd");
            $("#datepicker").val(ttst);
        }
        $("#seek").click();
    });

    $("#manager").click(function () {
        var strUrl = "../Admin/EventManage.aspx";
        location.href = strUrl;
    })

    $("#address").change(function () {
        var ss = $("#address option:selected").text();
        if (ss != "会议室") {
            $("#timeChange option[value='30分钟']").remove();
            var isExcase = true;
            for (var i = 0; i < $("#timeChange option").length; i++) {
                if ($("#timeChange ").get(0).options[i].text == "2小时") {
                    isExcase = false;
                }
            }
            if (isExcase) {
                $("#timeChange").prepend("<option value='2小时'>2小时</option>");
            }
        }
        if (ss == "会议室") {
            var isExcase = true;
            for (var i = 0; i < $("#timeChange option").length; i++) {
                if ($("#timeChange ").get(0).options[i].text == "30分钟") {
                    isExcase = false;
                }
            }
            if (isExcase) {
                $("#timeChange").prepend("<option value='30分钟'>30分钟</option>");
            }
            $("#timeChange option[value='2小时']").remove();
        }
        updatePeriodTimeByType($("#address option:selected").text());
        $("#seek").click();
    });
    $("#timeChange").change(function () {
        $("#seek").click();
    });

    function updatePeriodTimeByType(type) {
        var count = $("#timeChange option").length;
        if (type == "会议室") {
            for (var i = 0; i < count; i++) {
                if ($("#timeChange ").get(0).options[i].text == "30分钟") {
                    $("#timeChange ").get(0).options[i].selected = true;
                    break;
                }
            }
        }
        if (type == "培训室") {
            for (var i = 0; i < count; i++) {
                if ($("#timeChange ").get(0).options[i].text == "1小时") {
                    $("#timeChange ").get(0).options[i].selected = true;
                    break;
                }
            }
        }
        if (type == "俱乐部") {
            for (var i = 0; i < count; i++) {
                if ($("#timeChange ").get(0).options[i].text == "2小时") {
                    $("#timeChange ").get(0).options[i].selected = true;
                    break;
                }
            }
        }
        if (type == "篮球场") {
            for (var i = 0; i < count; i++) {
                if ($("#timeChange ").get(0).options[i].text == "2小时") {
                    $("#timeChange ").get(0).options[i].selected = true;
                    break;
                }
            }
        }
    }

    $("#layout").click(function () {
        var options = {
            type: "POST",
            url: "../Booking_chooseTime.asmx/layout",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: '{}',
            success: function (response) {
                if (response.d == "退出成功") {

                    location.href = "../Login.aspx";
                }
            },
            error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                alert('4' + status);
            }
        };
        $.ajax(options);
    })
    $('#seek').click(function () {
        $("#fiveDaysAgo, #fiveDaysNext").removeClass("hidden");
        dateChoose = $("#datepicker").val();
        periodTime = $("#timeChange").val(); //定义最小时间段
        type = $("#address").val();
        var address = $("#hidAdd").val();
        isVIP = "";
        var capacity = $("#capacity").val();
        var user = $("#hidUserName").val();
        var orgType1 = $("#hidUserType1").val();
        var orgType3 = $("#hidUserType3").val();
        var options = {
            type: "POST",
            url: "../Booking_chooseTime.asmx/Seek",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: '{"date":"' + dateChoose
                + '","type":"' + type
                + '","address":"' + address
                + '","isVIP":"' + isVIP
                + '","userName":"' + user
                + '","orgType1":"' + orgType1
                + '","orgType3":"' + orgType3
                + '","capacity":"' + capacity + '"}',
            success: function (response) {
                if (response != null) {
                    CreateTable(response.d);
                    altRows('MainTable');//设置样式
                    $("#confirm_div").addClass("hidden");
                }
            },
            error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                alert('5' + result.responseText);
            }
        };
        $.ajax(options);
    })

    function trim(str) {
        for (var i = 0  ; i < str.length && str.charAt(i) == "  "  ; i++);
        for (var j = str.length; j > 0 && str.charAt(j - 1) == "  "  ; j--);
        if (i > j) return "";
        return str.substring(i, j);
    }

    String.prototype.replaceAll = function (oldstr, newstr) {
        var oldlength =this.length;
        var ret = this.replace(oldstr, newstr);

        if (ret.split(oldstr).length>1)
            return ret.replaceAll(oldstr, newstr);
        return ret;
    }

    $("#update_instan").click(function () {
        var newInstan = $("#instanse").val()
        newInstan = newInstan.replaceAll("\n", "<br/>");
        var options = {
            type: "POST",
            url: "../Booking_chooseTime.asmx/updateInstanceByAdmin",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: '{"newInstance":"' + newInstan + '"}',
            success: function (response) {
                if (response.d != null) {
                    alert(response.d)
                }
            },
            error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                alert('7' + result.responseText);
            }
        };
        $.ajax(options);
    })

    $("input[name='btnLock']").click(function () {
        //获取周次的选择
        var passWord = "";
        var participants = "";
        var phoneNo = "";
        var cc = "";
        var meetingTheme = "";
        var meetingAbstract = "";
        var specialRequestFirst = "";
        var specialRequestSecond = "";
        var btnId = this.id;
        weekdays.splice(0, weekdays.length);//清空数组
        weeks.replace(weeks.toString(), "");//清空字符串
        //获取选中的星期
        $('#weekdays_div > input:checkbox:checked').each(function () {
            weekdays.push($(this).val());//星期转成数组
            weeks = weeks + $(this).val() + ",";//星期转成字符串
        })
        if (weeks.length > 2) {
            passWord = $("#passWord").val();
        }
        if (btnId == "btnSubmit")
        {
            participants = $("#tags").val();
            if (participants == "" || participants == null) {
                alert("请输入参加活动的人");
                return;
            }
            phoneNo = $("#phone").val();
            phoneNo = $.trim(phoneNo);
            if (phoneNo == "" || phoneNo == null) {
                alert("请输入您的电话号码");
                return;
            }
            var participant = [];
            participant = participants.split(';');
            for (var z = 0; z < participant.length; z++) {
                if (participant[z].split("@").length - 1 < 1 && $.trim(participant[z]) != "") {
                    alert("您输入的联系人不符，请校正");
                    return;
                }
            }
        }
        cc = $("#cc").val();
        meetingTheme = $("#meetingTheme").val();
        meetingAbstract = $("#meetingAbstract").val();
        //var mtrAdd = ""; $("#mtrAdd").val() + $("#SelectMtr option:selected").text();
        var mtrName = $("#SelectMtr option:selected").text();//?这里有点问题
        specialRequestFirst = $("#specialRequestFirst").val();
        specialRequestSecond = $("#specialRequestSecond").val();
        var startDate = $("#startDate").val();
        var startTime = $('#combobox').siblings('.custom-combobox').find('.ui-autocomplete-input').val(); //$("#startTime").val();
        var endDate = $("#endDate").val();
        var endTime = $('#combobox1').siblings('.custom-combobox').find('.ui-autocomplete-input').val();//$("#endTime").val();
        try {
            var option = {
                //async: false,
                type: "POST",
                url: "../Booking_chooseTime.asmx/Booking",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: '{"participants":"' + participants
                    + '","btnId":"' + btnId
                    + '","meetingTheme":"' + meetingTheme
                    + '","bookingVIP":"' + bookingVIP
                    + '","meetingAbstract":"' + meetingAbstract
                    + '","phoneNo":"' + phoneNo
                    + '","cc":"' + cc
                    + '","meetingRoomNo":"' + meetingRoomNo
                    + '","mtrName":"' + mtrName
                    + '","specialRequestFirst":"' + specialRequestFirst
                    + '","specialRequestSecond":"' + specialRequestSecond
                    + '","startDate":"' + startDate
                    + '","startTime":"' + startTime
                    + '","endDate":"' + endDate
                    + '","endTime":"' + endTime
                    + '","userName":"' + userName
                    + '","weeks":"' + weeks  
                    + '","passWord":"' + passWord
                    + '"}',
                success: function (response) {
                    if (response != null && response.d != null) {
                        alert(response.d);
                        //cleanAll();
                        if (response.d != "您预定的时间早于当前时间，请重新选择活动开始时间") {
                            $("#confirm_div").dialog("close");
                            $("#seek").click();
                        }
                    }
                },
                error: function (result, status) { 
                    alert('9' + result.responseText);
                },
                complete: function (response) {
                }
            };
            $.ajax(option);
        }
        catch (Exception) {
            alert('10' + Exception);
        }
    });
    //周期预定冲突检测
    function checkPeriodicConflict(wd) {
        var startDate = $("#startDate").val();
        var startTime = $('#combobox').siblings('.custom-combobox').find('.ui-autocomplete-input').val() //$("#startTime").val();
        var endDate = $("#endDate").val();
        var endTime = $('#combobox1').siblings('.custom-combobox').find('.ui-autocomplete-input').val()//$("#endTime").val();
        var options = {
            type: "POST",
            url: "../Booking_chooseTime.asmx/checkPeriodicConflict", 
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: '{"meetingRoomNo":"' + meetingRoomNo +
                      '","startDate":"' + startDate +
                      '","startTime":"' + startTime +
                       '","weekday":"' + wd +
                      '","endDate":"' + endDate +
                      '","endTime":"' + endTime +
                      '"}',
            success: function (response) {
                if (response != null) {
                    if (response.d.length > 0) {
                        alert(response.d);
                        return;
                    }
                }
            },
            error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                alert('11' + result.responseText);
            }
        };
        $.ajax(options);
    }
    $("#Button1").click(function () {
        $("#pas").dialog("close");
    })
    $("#passWord").keydown(function () {
        if (window.event.keyCode == 13) {
            $("#Button1").click();
        }
    })

    //星期选择
    $("input:radio[name = 'cycle']").click(function () {

        var cyc = $("input[name='cycle']:checked").val();//$("input:radio[name='cycle']:[checked]").val();
        if (cyc == "一周") {
            $("#weekdays_div").removeClass("hidden");
            $("#pas").dialog("open");
        }
        else if (cyc == "一次") {
            $("#pas").dialog("close");
            $("#weekdays_div").addClass("hidden");
            weekdays.splice(0, weekdays.length);//清空数组
            //所有取消选择
            $("#weekdays_div > input:checkbox:checked").removeAttr("checked");
        }
    })
});

function lock() {
    weeks.replace(weeks.toString(), "");//清空字符串
    //获取选中的星期
    $('#weekdays_div > input:checkbox:checked').each(function () {
        weeks = weeks + $(this).val() + ",";//星期转成字符串
    });
    var startDate = $("#startDate").val();
    var startTime = $('#combobox').siblings('.custom-combobox').find('.ui-autocomplete-input').val();
    var endDate = $("#endDate").val();
    var endTime = $('#combobox1').siblings('.custom-combobox').find('.ui-autocomplete-input').val();
};

//--------------------------------------------------- 
// 日期格式化 
// 格式 YYYY/yyyy/YY/yy 表示年份 
// MM/M 月份 
// W/w 星期 
// dd/DD/d/D 日期 
// hh/HH/h/H 时间 
// mm/m 分钟 
// ss/SS/s/S 秒 
//---------------------------------------------------parseInt(this.getMonth()+1)
Date.prototype.Format = function (formatStr) {
    var str = formatStr;
    var Week = ['日', '一', '二', '三', '四', '五', '六'];

    str = str.replace(/yyyy|YYYY/, this.getFullYear());
    str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));

    str = str.replace(/MM/, (parseInt(this.getMonth()+1) > 9 ? parseInt(this.getMonth()+1).toString() : ('0' + parseInt(this.getMonth()+1) ) ) );
    str = str.replace(/M/g, this.getMonth());

    str = str.replace(/w|W/g, Week[this.getDay()]);

    str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
    str = str.replace(/d|D/g, this.getDate());

    str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
    str = str.replace(/h|H/g, this.getHours());
    str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
    str = str.replace(/m/g, this.getMinutes());

    str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
    str = str.replace(/s|S/g, this.getSeconds());
    return str;
}

//+--------------------------------------------------- 
//| 字符串转成日期类型 
//| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd 
//+--------------------------------------------------- 
function StringToDate(DateStr) {
    var converted = Date.parse(DateStr);
    var myDate = new Date(converted);
    if (isNaN(myDate)) {
        //var delimCahar = DateStr.indexOf('/')!=-1?'/':'-'; 
        var arys = DateStr.split('-');
        myDate = new Date(arys[0], --arys[1], arys[2]);
    }
    return myDate;
}

function goback() {
    $("#bg").css("display", "none");
    $("#confirm_div").css("display", "none");
};

Date.prototype.DateAdd = function (strInterval, Number) {
    var dtTmp = this;
    switch (strInterval) {
        case 's': return new Date(Date.parse(dtTmp) + (1000 * Number));
        case 'n': return new Date(Date.parse(dtTmp) + (60000 * Number));
        case 'h': return new Date(Date.parse(dtTmp) + (3600000 * Number));
        case 'd': return new Date(Date.parse(dtTmp) + (86400000 * Number));
        case 'w': return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
        case 'q': return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number * 3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
        case 'm': return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
        case 'y': return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
    }
}

Date.prototype.DateSub = function (strInterval, Number) {
    var dtTmp = this;
    switch (strInterval) {
        case 's': return new Date(Date.parse(dtTmp) - (1000 * Number));
        case 'n': return new Date(Date.parse(dtTmp) - (60000 * Number));
        case 'h': return new Date(Date.parse(dtTmp) - (3600000 * Number));
        case 'd': return new Date(Date.parse(dtTmp) - (86400000 * Number));
        case 'w': return new Date(Date.parse(dtTmp) - ((86400000 * 7) * Number));
        case 'q': return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) - Number * 3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
        case 'm': return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) - Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
        case 'y': return new Date((dtTmp.getFullYear() - Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
    }
}

function getDate(strDate) {
    var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
     function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
    return date;
}

function CreateTable(list) {
    $("#MainTable,#next_div").remove();

    $("#divEvent").remove();
    $("#form1").append("<div id='divEvent'></div>");

    mtrList = list; //变成全局变量
    var weekday = new Array(7);{
        weekday[0] = "星期日"
        weekday[1] = "星期一"
        weekday[2] = "星期二"
        weekday[3] = "星期三"
        weekday[4] = "星期四"
        weekday[5] = "星期五"
        weekday[6] = "星期六"
    };
    var divs = "";
    var content;
    content = "<div id='contain'><table id ='MainTable' class='altrowstable' freezeRowNum='0' freezeColumnNum='1'><tr><td colspan ='100' id='td1' class = 'td1'><p><h1>会议室预约情况</h1></p></td></tr>"
            + " <tr>"
            + " <th rowspan='2' style='width:80px;padding:0'><div class='out'> <b>时间</b> <em>场地</em></div></th>"
    var dd = getDate(dateChoose); 

    var timestart = getDate(dateChoose);//new Date()
    if (periodTime == "30分钟") {
        for (var aa = 0; aa < days; aa++) {
            var sdt = dd.Format("yyyy-MM-dd").toString();
            content += "<th colspan ='19' name = '" + sdt + "'>" + sdt.split("-")[0] + "年" + (sdt.split("-")[1]) + "月" + sdt.split("-")[2] + "日  " + weekday[dd.getDay()] + "</th>";
            dd = dd.DateAdd("d", 1);
        }
        content += "</tr><tr> ";
        timestart.setHours(8);
        timestart.setMinutes(0);
        timestart.setSeconds(0);
        for(var bb = 1; bb <= days; bb++) {
            var sdt = (timestart.getFullYear() + "-" + ((timestart.getMonth() + 1) > 10 ? (timestart.getMonth() + 1) : "0"+(timestart.getMonth() + 1))+ "-" + timestart.getDate()).toString();
            do {
            //for (var dth = 0; dth < 17; dth++) {
                var hou = timestart.getHours() < 10 ? ("0" + timestart.getHours()) : timestart.getHours();
                var min = timestart.getMinutes() == 0 ? (timestart.getMinutes() + "0") : timestart.getMinutes();
                var showHalfHour = (hou + ":" + min.toString()).toString();
                var thid = "th" + sdt + hou + min;
                content += "<th id = '" + thid + "'>" + showHalfHour + "</th>";
                timestart = timestart.DateAdd("n", 30);
            }
            //}
            while (timestart.getHours() < 17 || timestart.getHours() == 17 && timestart.getMinutes() < 1);

            timestart = timestart.DateAdd("d", 1);
            timestart.setHours(8);
            timestart.setMinutes(0);
            timestart.setSeconds(0);
        }
    }
    else if (periodTime == "1小时") {
        if (type != "会议室") {
            for (var aa = 0; aa < days; aa++) {
                var sdt = dd.Format("yyyy-MM-dd").toString();
                content += "<th colspan ='16' name = '" + sdt + "'>" + sdt.split("-")[0] + "年" + (sdt.split("-")[1]) + "月" + sdt.split("-")[2] + "日  " + weekday[dd.getDay()] + "</th>";
                var dd = dd.DateAdd("d", 1);
            }
            content += "</tr><tr> ";
            //timestart = new Date();
            timestart.setHours(8);
            timestart.setMinutes(0);
            timestart.setSeconds(0);
            for (var bb = 1; bb <= days; bb++) {
                var sdt = (timestart.getFullYear() + "-" + ((timestart.getMonth() + 1) > 10 ? (timestart.getMonth() + 1) : "0" + (timestart.getMonth() + 1)) + "-" + timestart.getDate()).toString();
                do {
                    var hou = timestart.getHours() < 10 ? ("0" + timestart.getHours()) : timestart.getHours();
                    var showHour = (hou + ":00").toString();
                    var thid = "th" + sdt + hou + "00";
                    content += "<th id = '" + thid + "'>" + showHour + "</th>";
                    timestart = timestart.DateAdd("h", 1);
                }
                while (timestart.getHours() != 0);
                timestart = timestart.DateAdd("d", 1);
                timestart.setHours(8);
                timestart.setMinutes(0);
                timestart.setSeconds(0);
            }
        }
        else if (type == "会议室") {
            for (var aa = 0; aa < days; aa++) {
                var sdt = dd.Format("yyyy-MM-dd").toString();
                content += "<th colspan ='10' name = '" + sdt + "'>" + sdt.split("-")[0] + "年" + (sdt.split("-")[1]) + "月" + sdt.split("-")[2] + "日  " + weekday[dd.getDay()] + "</th>";
                var dd = dd.DateAdd("d", 1);
            }
            content += "</tr><tr> ";
            //timestart = new Date();
            timestart.setHours(8);
            timestart.setMinutes(0);
            timestart.setSeconds(0);
            for (var bb = 1; bb <= days; bb++) {
                var sdt = (timestart.getFullYear() + "-" + ((timestart.getMonth() + 1) > 10 ? (timestart.getMonth() + 1) : "0" + (timestart.getMonth() + 1)) + "-" + timestart.getDate()).toString();
                do {
                    var hou = timestart.getHours() < 10 ? ("0" + timestart.getHours()) : timestart.getHours();
                    var showHour = (hou + ":00").toString();
                    var thid = "th" + sdt + hou + "00";
                    content += "<th id = '" + thid + "'>" + showHour + "</th>";
                    timestart = timestart.DateAdd("h", 1);
                }
                while (timestart.getHours() <= 17);
                timestart = timestart.DateAdd("d", 1);
                timestart.setHours(8);
                timestart.setMinutes(0);
                timestart.setSeconds(0);
            }
        }
    }
    else if (periodTime == "2小时") {
        for (var aa = 0; aa < days; aa++) {
            var sdt = dd.Format("yyyy-MM-dd").toString();
            content += "<th colspan ='8' name = '" + sdt + "'>" + sdt.split("-")[0] + "年" + (sdt.split("-")[1]) + "月" + sdt.split("-")[2] + "日  " + weekday[dd.getDay()] + "</th>";
            var dd = dd.DateAdd("d", 1);
        }
        content += "</tr><tr> ";
        //timestart = new Date();
        timestart.setHours(8);
        timestart.setMinutes(0);
        timestart.setSeconds(0);
        for (var bb = 1; bb <= days; bb++) {
            var sdt = (timestart.getFullYear() + "-" + ((timestart.getMonth() + 1) > 10 ? (timestart.getMonth() + 1) : "0" + (timestart.getMonth() + 1)) + "-" + timestart.getDate()).toString();
            do {
                var hou = timestart.getHours() < 10 ? ("0" + timestart.getHours()) : timestart.getHours();
                var showHour = (hou + ":00").toString();
                var thid = "th" + sdt + hou + "00";
                content += "<th id = '" + thid + "'>" + showHour + "</th>";
                timestart = timestart.DateAdd("h", 2);
            }
            while (timestart.getHours() != 0);
            timestart = timestart.DateAdd("d", 1);
            timestart.setHours(8);
            timestart.setMinutes(0);
            timestart.setSeconds(0);
        }
    }
    else if (periodTime == "10分钟") {
        for (var aa = 0; aa < 1; aa++) {
            var sdt = dd.Format("yyyy-MM-dd").toString();
            content += "<th colspan ='55' name = '" + sdt + "'>" + sdt.split("-")[0] + "年" + (sdt.split("-")[1]) + "月" + sdt.split("-")[2] + "日  " + weekday[dd.getDay()] + "</th>";
        }
        content += "</tr><tr> ";
        timestart.setHours(8);
        timestart.setMinutes(0);
        timestart.setSeconds(0);
        for (var bb = 1; bb <= 1; bb++) {
            var sdt = (timestart.getFullYear() + "-" + ((timestart.getMonth() + 1) > 10 ? (timestart.getMonth() + 1) : "0" + (timestart.getMonth() + 1)) + "-" + timestart.getDate()).toString();
            do {
                var hou = timestart.getHours() < 10 ? ("0" + timestart.getHours()) : timestart.getHours();
                var min = timestart.getMinutes() == 0 ? (timestart.getMinutes() + "0") : timestart.getMinutes();
                var showTenMins = (hou + ":" + min.toString()).toString();
                var thid = "th" + sdt + hou + min;
                content += "<th id = '" + thid + "'>" + showTenMins + "</th>"
                timestart = timestart.DateAdd("n", 10);
            }
            while (timestart.getHours() < 17 || timestart.getHours() == 17 && timestart.getMinutes() < 1);
        }
    }
    content += "</tr>";
    $("#SelectMtr").empty();
    for (var i = 0; i < list.length; i++)
    {
        $("#SelectMtr").append("<option value = '" + list[i].mtrId + "'>" + list[i].mtrName + "</option>");
        var capacity = list[i].mtrCapacity;     //获取会议室容量
        var isVIP = list[i].mtrType;//获取会议室类型VIP or not
        var address = list[i].mtrAddress;//获取会议室地址
        var photo = list[i].mtrPhoto;//获取会议室照片
        var phone = list[i].mtrPhone;//获取会议室电话
        var hasProjector = false;
        var hasTelephone = false;
        //循环查询会议室是否有投影仪
        for (var j = 0; j < list[i].listMtrRes.length; j++) {
            var resName = list[i].listMtrRes[j].resName
            if (resName == "投影仪") {
                hasProjector = true;
            }
        }
        for (var j = 0; j < list[i].listMtrRes.length; j++) {
            var resName = list[i].listMtrRes[j].resName
            if (resName == "三角电话") {
                hasTelephone = true;
            }
        }
        content += "<tr>";
        if (isVIP == "VIP") {
            content += " <td class ='vip t1' name = '" + list[i].mtrId + "'>" + "<span>" + list[i].mtrName + "</span><p>";
        }
        if (isVIP != "VIP") {
            content += " <td class ='t1' name = '" + list[i].mtrId + "'>" + "<span>" + list[i].mtrName + "</span><p>";
        }
        if (hasProjector == true) {
            content += "<span><img src='../image/proj.png'></span>";
        }
        if (hasTelephone == true) {
            content += "<span><img src='../image/Tritel.png'></span>";  //"<span title =" + list[i].mtrPhone + "><img src='../image/telep.png'></span>";
        }
        content += "<span>" + capacity + "</span>";
        content += "</p></td>"; //第一个单元格
        //开始接下来的单元格
        if (periodTime == "30分钟") {
            for (var k = 1; k < (19 * days + 1) ; k++) {
                content += "<td></td>";
            }
        }
        else if (periodTime == "1小时") {
            if (type != "会议室") {
                for (var k = 1; k < (16 * days + 1) ; k++) {
                    content += "<td></td>";
                }
            }
            else if (type == "会议室") {
                for (var k = 1; k < (10 * days + 1) ; k++) {
                    content += "<td></td>";
                }
            }
        }
        else if (periodTime == "2小时") {
            for (var k = 1; k < (8 * days + 1) ; k++) {
                content += "<td></td>";
            }
        }
        else if (periodTime == "10分钟") {
            for (var k = 1; k < (55 + 1) ; k++) {
                content += "<td></td>";
            }
        }
        content += "</tr>";
    }
    content += "</table></div>";//<input id='next_div' type='button' value='下一步'/>
    $("#divTable").append(content);

    for (var i = 0; i < mtrList.length; i++) {
        var state = list[i].mtrState;//会议室的状态,若状态不可用，改变样式
        if (!(list[i].mtrState)) {
            var ids = "stateflase" + list[i].mtrId;
            var mtr = mtrList[i];
            creatFreezeDiv(periodTime, ids, mtr);
        }
        for (var e_div = 0; e_div < mtrList[i].listMtrEvent.length ; e_div++) {
            //一次预定事件 74bfc644-4431-4a03-8e80-c5d91ec7c80d
            if (!mtrList[i].listMtrEvent[e_div].BookingSchedul[0].isPeriodic || mtrList[i].listMtrEvent[e_div].BookingSchedul[0].isPeriodic == null) {
                var ids = ((mtrList[i].listMtrEvent[e_div].bookingID).toString() + "ed" + mtrList[i].mtrId).toString(); //组合起来的ID名称
                var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                var mtr = mtrList[i]; //事件的会议室 a6eb099f-cd40-4e93-924a-878cbc444f7a
                creatEventDiv(periodTime, ids, eve, mtr);
            }
            //周次周期预定事件
            else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].isPeriodic) {
                //周期事件开始时间 float
                var pEveStDt = parseFloat(mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate.substr(6, 13));
                //周期事件结束时间 float
                var pEveEtDt = parseFloat(mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate.substr(6, 13));
                //当前日期
                for (var ar = 0; ar <= days; ar++) {
                    //当前显示的日期
                    var pEve = Date.parse(dateChoose.replace("-", "/").replace("-", "/")) - 1000 * 60 * 60 * 8 + 1000 * 60 * 60 * 24 * ar;
                    if (pEve >= pEveStDt && pEve <= pEveEtDt) //当前要显示的日期在事件的范围内
                    {
                        if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Monday && EngWeekdays[new Date(pEve).getDay()] == "Monday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/"; 
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; 
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic1" + mtrList[i].mtrId).toString()).toString(); //组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                        else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Tuesday && EngWeekdays[new Date(pEve).getDay()] == "Tuesday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/";     //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic2" + mtrList[i].mtrId).toString()).toString(); //组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                        else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Wednesday && EngWeekdays[new Date(pEve).getDay()] == "Wednesday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/";     //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic3" + mtrList[i].mtrId).toString()).toString(); //组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                        else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Thursday && EngWeekdays[new Date(pEve).getDay()] == "Thursday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/";     //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic4" + mtrList[i].mtrId).toString()).toString();//组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                        else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Friday && EngWeekdays[new Date(pEve).getDay()] == "Friday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/";     //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic5" + mtrList[i].mtrId).toString()).toString(); //组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                        else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Saturday && EngWeekdays[new Date(pEve).getDay()] == "Saturday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/";     //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic6" + mtrList[i].mtrId).toString()).toString(); //组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                        else if (mtrList[i].listMtrEvent[e_div].BookingSchedul[0].Sunday && EngWeekdays[new Date(pEve).getDay()] == "Sunday") {
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingStartDate = "/Date(" + pEve + ")/";     //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            mtrList[i].listMtrEvent[e_div].BookingSchedul[0].meetingEndDate = "/Date(" + pEve + ")/"; //new Date(Date.parse(pEve)).Format("yyyy-MM-DD");
                            var ids = ((mtrList[i].listMtrEvent[e_div].bookingID + "Periodic7" + mtrList[i].mtrId).toString()).toString(); //组合起来的ID名称
                            var eve = mtrList[i].listMtrEvent[e_div];  //一个预定事件
                            var mtr = mtrList[i]; //事件的会议室
                            creatEventDiv(periodTime, ids, eve, mtr);
                        }
                    }
                }
            }
        }
    }


    //首行变色
        $("#MainTable tr:gt(2)").mouseover(function () {
            try {
                $(this).find("td:eq(0)").addClass('td_hover');
            }
            catch(Exception){
                return;
            }
        })
        .mouseout(function () {
            try {
                $(this).find("td:eq(0)").removeClass('td_hover');
            }
            catch(Exception){
                return ;
            }
        });
    //自身变色
    $("#MainTable tr td:gt(3)").hover(
        function () {
            $(this).addClass('td_hover');
        },
        function () {
            $(this).removeClass('td_hover');
        }
    );
    //首列变色
    $("#MainTable tr td:gt(0)").mouseover(function () {
        //找到td的前一个序号
        var tdSeq = $(this).parent().find('> td').index($(this)[0]) - 1 ;//
        if (tdSeq < 0) return;
        //找到tr的后一个序号
        var dtrSeq = $(this).parent().parent().find('>tr').index($(this).parent()[0]) + 1 ;//
        //当前td的前一个的样式是什么颜色，背景色就是什么颜色
        //$("#MainTable tr:eq(2) td:eq(" + tdSeq + ")")[0].bgColor = $("#MainTable tr:eq(2) td:eq(" + tdSeq + ")")[0].style.backgroundColor;
        //当前td的前一个的样式改成红色
        $("#MainTable tr:eq(2) th:eq(" + tdSeq + ")").addClass('td_hover');
    })
    .mouseout(function () {
     	var tdSeq = $(this).parent().find('> td').index($(this)[0]) - 1 ;//
     	if (tdSeq < 0) return;
     	$("#MainTable tr:eq(2) th:eq(" + tdSeq + ")").removeClass('td_hover');
    });
    var trStr;//起点行号
    var tdStr;//起点列号
    var trEnd;//结束点行号
    var trEnd;//结束点列号
    var bSelect = false;

    //$("#MainTable").click(function () {
    //    //$("#confirm_div").addClass("hidden");//隐藏div
    //    //$("#MainTable").removeClass("opacity");//变透明50%
    //});
    //双击从这里跳转
    $("div[name='evedivs']").dblclick(function () {
        var eId = $(this).attr("id").substr(0,36);
        location.href = "ShowInfor.aspx?id="+eId;
        //Server.Transfer("../WEB/ShowInfor.aspx?id=1", true);
    });
    $("#bg").dblclick(function () {
        goback();
    });
    $(".t1").mouseover(function () {
        $("#effect").empty();
        var divAddress;
        var divCompany;
        var divDept;
        var divPhone;
        var divRes;
        var divRes = "资源： ";
        $(this)[0].name;
        for (var ds = 0; ds < list.length; ds++) {
            if (list[ds].mtrId == $(this)[0].name) {
                divAddress = list[ds].mtrAddress + list[ds].mtrAddress1;
                divCompany = list[ds].mtrCompanyRuc;
                divDept = list[ds].mtrDeptRuc;
                divPhone = list[ds].mtrPhone;
                for (var dsr = 0; dsr < list[ds].listMtrRes.length; dsr++) {
                    divRes = divRes + list[ds].listMtrRes[dsr].resName + "  ";
                }
            }
        }
        var detil = "<h3 class='ui-widget-header ui-corner-al'>详细信息</h3><p>地址：" + divAddress + "</p><br/> <p>电话：" + divPhone + "</p><br/><p>" + divRes + "</p>";
        $("#effect").append(detil);

        var dleft = $(this).offset().left;//maintable相当于窗口的左边的偏移量
        var dtop = $(this).offset().top;//maintable元素相对于窗口的上边的偏移量
        var dtdWidth = $(this).width() + dleft; //$('#MainTable').find('tr:eq(' +2+ ')').find('td:eq(' +1+ ')')    //td的宽度
        var dtdHeight = $(this).height() + 2;//td的高度 
        $("#effect").css("z-index", "3");
        $("#effect").css("position", "absolute");
        $("#effect").css("top", dtop + "px");
        $("#effect").css("left", dtdWidth + "px");

        $(".toggler").show("slow");

        $(".t1").mouseout(function () {
            $(".toggler").hide("slow");
            //$("#effect").empty();
        });
    });
    $("#MainTable tr td:not(.t1)").mousedown(function () {//:gt(2)
        if ($("*").hasClass("selected")) $("*").removeClass("selected");
        //获得table的行号
        var trStr = $(this).parent().parent().find('>tr').index($(this).parent()[0]);
        startTrSeq = trStr;
        //获得table的列号
        var tdStr = $(this).parent().find('>td').index($(this)[0]) + 1;
        startTdSeq = tdStr;
        $(this).addClass("selected");
        //查找开始时间  第3行，第tdStr列
        startTime = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (tdStr - 2) + ')').text();
        //查找事件开始的日期
        startDate = $('#MainTable').find('tr:eq(' + 1 + ')').find('th:eq(' + findDate(tdStr) + ')').text();
        //查找所选会议室名称  第trStr行，第1列
        meetingRoomNo = $("#MainTable").find("tr:eq(" + trStr + ")").find("td:eq(0)").attr("name");
        if ($("#MainTable").find("tr:eq(" + trStr + ")").find("td:eq(0)").attr('class').substr(0, 3) == "vip")
        {
            bookingVIP = "VIP";
        }
        else if ($("#MainTable").find("tr:eq(" + trStr + ")").find("td:eq(0)").attr('class').substr(0, 3) != "vip") {
            bookingVIP = "普通";
        }
        //设置确认表显示所选会议室
        var count1 = $("#SelectMtr option").length;
        for (var i = 0; i < count1; i++)
        {
            if ($("#SelectMtr").get(0).options[i].value == meetingRoomNo)
            {
                $("#SelectMtr").get(0).options[i].selected = true;
                break;
            }
        }
        var count = $("#startTime option").length;
        //为第一个combobox赋值
        //$('#combobox').siblings('.custom-combobox').find('.ui-autocomplete-input').val(startTime);
        for (var i = 0; i < count; i++) {
            if ($("#startTime").get(0).options[i].text == startTime) {
                $("#startTime").get(0).options[i].selected = true;
                break;
            }
        }
        bSelect = true;
    });
    
    $("#MainTable tr td:not(.t1)").mouseover(function () {
        //获得table的行号
        var trStr = $(this).parent().parent().find('>tr').index($(this).parent()[0]);
        //获得table的列号
        var tdStr = $(this).parent().find('>td').index($(this)[0]);//当前列号
        if (bSelect) {
            //right
            if (tdStr > startTdSeq) {
                maxTd = maxTd > tdStr ? maxTd : tdStr;
                var st = startTdSeq; //< tdStr ? startTdSeq : tdStr;
                var et = tdStr;// startTdSeq < tdStr ? tdStr : startTdSeq;
                for (var jj = st; jj <= et; jj++) {
                    $('#MainTable').find('tr:eq(' + startTrSeq + ')').find('td:eq(' + jj + ')').addClass("selected");
                }
                for (var jjj = et + 1; jjj < maxTd + 1; jjj++) {
                    $('#MainTable').find('tr:eq(' + startTrSeq + ')').find('td:eq(' + jjj + ')').removeClass("selected");
                }
            }
            //left
            if (tdStr < startTdSeq) {
                minTd = minTd < tdStr ? minTd : tdStr;
                var st = tdStr;// startTdSeq < tdStr ? startTdSeq : tdStr;
                var et = startTdSeq;//< tdStr ? tdStr : startTdSeq;
                for (var jj = st; jj < et; jj++) {
                    $('#MainTable').find('tr:eq(' + startTrSeq + ')').find('td:eq(' + jj + ')').addClass("selected");
                }
                for (var jjj = minTd; jjj < st; jjj++) {
                    $('#MainTable').find('tr:eq(' + startTrSeq + ')').find('td:eq(' + jjj + ')').removeClass("selected");
                }
            }
        }
    });

    $("#MainTable tr td:not(.t1)").mouseup(function () {
        bSelect = false;
        //获得table的行号
        var trEnd = $(this).parent().parent().find('>tr').index($(this).parent()[0]) ;
        //获得table的列号
        var tdEnd = $(this).parent().find('>td').index($(this)[0]) + 1;
        endTime1 = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (tdEnd - 2) + ')').text();
        endDate = $('#MainTable').find('tr:eq(' + 1 + ')').find('th:eq(' + findDate(tdEnd) + ')').text();
        if (startDate != endDate) {
            alert("您的选择跨天，请重新选择");
            $("#seek").click();
            return;
        }
        if (parseInt(startTime.split(':')[0] + startTime.split(':')[1]) > parseInt(endTime1.split(':')[0] + endTime1.split(':')[1])) {
            var temp = startTime;
            startTime = endTime1;
            endTime1 = temp;
        }
        //if (periodTime == "30分钟") {
        //    var kkk = new Date();
        //    kkk.setHours(endTime1.split(":")[0]);
        //    kkk.setMinutes(endTime1.split(":")[1]);
        //    kkk.setSeconds(0);
        //    kkk = kkk.DateAdd("n", "30");
        //    endTime = (kkk.getHours() < 10 ? ("0" + kkk.getHours().toString()) : kkk.getHours().toString())
        //        + ":" + (kkk.getMinutes() == 0 ? "00" : kkk.getMinutes()).toString();
        //}
        //else if (periodTime == "2小时") {
        //    var kkk = new Date();
        //    kkk.setHours(endTime1.split(":")[0]);
        //    kkk.setMinutes(endTime1.split(":")[1]);
        //    if (endTime1.split(":")[0] == "22") {
        //        kkk = kkk.DateAdd("n", "119");
        //    }
        //    else {
        //        kkk = kkk.DateAdd("n", "120");
        //    }
        //    kkk.setSeconds(0);
        //    endTime = (kkk.getHours() < 10 ? ("0" + kkk.getHours().toString()) : kkk.getHours().toString()) + ":" + (kkk.getMinutes() == 0 ? "00" : kkk.getMinutes()).toString();
        //}
        //else if (periodTime == "1小时") {
        //    //if (type != "会议室") {
        //    var kkk = new Date();
        //    kkk.setHours(endTime1.split(":")[0]);
        //    kkk.setMinutes(endTime1.split(":")[1]);
        //    if (endTime1.split(":")[0] == "23") {
        //        kkk = kkk.DateAdd("n", "59");
        //    }
        //    else {
        //        kkk = kkk.DateAdd("n", "60");
        //    }
        //    kkk.setSeconds(0);
        //    endTime = (kkk.getHours() < 10 ? ("0" + kkk.getHours().toString()) : kkk.getHours().toString()) + ":" + (kkk.getMinutes() == 0 ? "00" : kkk.getMinutes()).toString();
        //}
        endTime = endTime1;
        var count = $("#endTime option").length;
        $('#combobox').siblings('.custom-combobox').find('.ui-autocomplete-input').val(startTime);
        $('#combobox1').siblings('.custom-combobox').find('.ui-autocomplete-input').val(endTime);
        for (var i = 0; i < count; i++) {
            if ($("#endTime").get(0).options[i].text == endTime) {
                $("#endTime").get(0).options[i].selected = true;
                $("#combobox").val(endTime);
                break;
            }
        }
        nextStep();
        //checkConflict();
    });
    //预定冲突检测
    function checkConflict() {
        try {
            var option = {
                type: "POST",
                url: "../Booking_chooseTime.asmx/checkConflict",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: '{"meetingRoomNo":"' + meetingRoomNo +
                      '","startDate":"' + startDate +
                      '","startTime":"' + startTime +
                      '","endDate":"' + endDate +
                      '","endTime":"' + endTime  + '"}',
                success: function (response) {
                    if (response != null) {
                        if (response.d.length > 0) {
                            alert(response.d);
                        }
                        else {
                            nextStep();
                        }
                    }
                },
                error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                    alert('12' + result.responseText);
                }
            };
            $.ajax(option);
        }
        catch (Exception) {
            alert('13' + Exception);
        }
    }
    function nextStep() {
        dateTrans();//数据传递
        $("#bg").css("display","block");
        $("#confirm_div").dialog("open");
        $("#weekdays_div").addClass("hidden");
        $("tags").focus();//获取焦点
    }

    function letDivCenter(divName) {
        var top = ($(window).height() - $(divName).height()) / 2;
        var left = ($(window).width() - $(divName).width()) / 2;
        var scrollTop = $(document).scrollTop();
        var scrollLeft = $(document).scrollLeft();
        $(divName).css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
    }
    $("#SelectMtr").change(function () {
        //获取选中的会议室名称
        var mName = $("#SelectMtr").find("option:selected").text();
        for (var i = 0; i < mtrList.length; i++)
        {
            if(mtrList[i].mtrName==mName){
                $("#mtrAdd").attr("value",(mtrList[i].mtrAddress+mtrList[i].mtrAddress1));
                break;
            }
        }
    })
}
//传递数据
function dateTrans() {
    for (var i = 0; i < mtrList.length; i++)
    {
        if (mtrList[i].mtrId == meetingRoomNo)
        {
            $("#mtrAdd").attr("value", (mtrList[i].mtrAddress + mtrList[i].mtrAddress1));
        }
    }
    var std = startDate.split(" ")[0];
    var newStd = std.replace("年", "-").replace("月", "-").replace("日", "");
    var newEnd = endDate.split(" ")[0].replace("年", "-").replace("月", "-").replace("日", "")
    $("#startDate").attr("value", newStd);
    $("#combobox").attr("value", newStd);
    $("#endDate").attr("value", newEnd);
}

function findDate(tdStr) {
    if (periodTime == "30分钟") {
        dStr = parseInt(((tdStr - 2) / 19) + 1);
    }
    else if (periodTime == "1小时") {
        if (type != "会议室") {
            dStr = parseInt(((tdStr - 2) / 16) + 1);
        }
        else if (type == "会议室") {
            dStr = parseInt(((tdStr - 2) / 10) + 1);
        }
    }
    else if (periodTime == "2小时") {
        dStr = parseInt(((tdStr - 2) / 8) + 1)
    }
    else if (periodTime == "10分钟") {

        dStr = parseInt(((tdStr - 2) / 55) + 1)
    }
    return dStr;
}


function altRows(id) {
    if (document.getElementsByTagName) {
        var table = document.getElementById(id);
        var rows = table.getElementsByTagName("tr");
        for (i = 0; i < rows.length; i++) {
            if (i % 2 == 0) {
                rows[i].className = "evenrowcolor";
            } else {
                rows[i].className = "oddrowcolor";
            }
        }
    }
}

function creatEventDiv(periodTime, ids, eve, mtr) {
    var mName = mtr.mtrId;//取出event所属的会议室名称
    var left = $("#MainTable").offset().left;//maintable相当于窗口的左边的偏移量
    var top = $("#MainTable").offset().top;//maintable元素相对于窗口的上边的偏移量
    var pleft = $("#MainTable").scrollLeft();//maintable元素相对于滚动条左边的偏移量
    var pTop = $("#MainTable").scrollTop();//maintable元素相对于滚动条顶部的偏移量 
    var tdWidth = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').width(); //$('#MainTable').find('tr:eq(' +2+ ')').find('td:eq(' +1+ ')')    //td的宽度
    var tdHeight = $("td[name='" + mtr.mtrId + "']").height() + 1;//td的高度  $("td[class='t1']").
    if (eve.BookingSchedul[0] != null) {
        var bssd = (new Date(parseFloat((eve.BookingSchedul[0].meetingStartDate).substr(6, 13)))).Format("yyyy-MM-dd");
        //取出event开始的格子   new Date(parseFloat((eve.BookingSchedul[0].meetingStartDate).substr(6, 13)))
        var bsst = eve.BookingSchedul[0].startTime;
        //取出event所在的结束日期
        var bsed = (new Date(parseFloat((eve.BookingSchedul[0].meetingEndDate).substr(6, 13)))).Format("yyyy-MM-dd");
        //取出event结束的时间
        var bset = eve.BookingSchedul[0].endTime;
        //计算分钟差
        var mins = timeSpan(bssd, bsst, bsed, bset);
        //开始的行号
        var trIndex = $("td[name='" + mName + "']").parent().parent().find('tr').index($("td[name='" + mName + "']").parent()[0]);
        var evetop = $("td[name='" + mName + "']").offset().top;
        if (periodTime == "30分钟") {
            //整个table包含的个5分钟（基本单位）
            var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '17:30');
            var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
            var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (19 * days - 1) + ')').offset().left + tdWidth;
            //整个tabled的宽度
            var tableWid = lasttd - firsttd;
            //div开始的像素点 eveSt
            var dSub = parseInt((getDate(bssd) - getDate(dateChoose)) / 86400000);
            var eveSt = (timeSpan(dateChoose, '08:00', bssd, bsst) - dSub * 14.5 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
            //判断周期性预定是否超出表格
            if (eveSt < firsttd || eveSt > lasttd) {
                return;
            }
            //div结束的像素点 eveEd
            var eveEd = (timeSpan(dateChoose, '08:00', bsed, bset) - dSub * 14.5 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
            wid = eveEd - eveSt;
            var divs = "<div border=1 class='evedivs' id='" + ids + "' name='evedivs' title='" + eve.BookingSchedul[0].undefine2 + "'>"
                + eve.meetingTheme + "<br/>" + eve.bookingPerson + "</div>";//+ eve.BookingSchedul[0].startTime + eve.BookingSchedul[0].endTime
            $("#divEvent").append(divs);
        }
        else if (periodTime == "1小时") {
            if (type != "会议室") {
                //整个table包含的个5分钟（基本单位）
                var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '23:59');
                var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
                var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (16 * days - 1) + ')').offset().left + tdWidth;
                //整个tabled的宽度
                var tableWid = lasttd - firsttd;
                //div开始的像素点 eveSt
                var dSub = parseInt((getDate(bssd) - getDate(dateChoose)) / 86400000);
                var eveSt = (timeSpan(dateChoose, '08:00', bssd, bsst) - dSub * 8 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
                //判断周期性预定是否超出表格
                if (eveSt < firsttd || eveSt > lasttd) {
                    return;
                }
                var eveEd = (timeSpan(dateChoose, '08:00', bsed, bset) - dSub * 8 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
                wid = eveEd - eveSt;
                var divs = "<div border=1 class='evedivs' id='" + ids + "' name='evedivs' title='" + eve.BookingSchedul[0].undefine2 + "'>"
                     + eve.meetingTheme + "<br/>" + eve.bookingPerson + "</div>";
                $("#divEvent").append(divs);
            }
            else if (type == "会议室") {
                var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '18:00');
                var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
                var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (10 * days - 1) + ')').offset().left + tdWidth;
                //整个tabled的宽度
                var tableWid = lasttd - firsttd;
                //判断周期性预定是否超出表格
                if (eveSt < firsttd || eveSt > lasttd) {
                    return;
                }
                //div开始的像素点 eveSt
                var dSub = parseInt((getDate(bssd) - getDate(dateChoose)) / 86400000);
                var eveSt = (timeSpan(dateChoose, '08:00', bssd, bsst) - dSub * 14 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
                //div结束的像素点 eveEd
                var eveEd = (timeSpan(dateChoose, '08:00', bsed, bset) - dSub * 14 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
                //var lastDay = (new Date(parseFloat( Date.parse(dateChoose) + 1000 * 60 * 60 * 24 * days ))).Format("yyyy-MM-dd");
                wid = eveEd - eveSt;
                var divs = "<div border=1 class='evedivs' id='" + ids + "' name='evedivs' title='" + eve.BookingSchedul[0].undefine2 + "'>"
                     + eve.meetingTheme + "<br/>" + eve.bookingPerson + "</div>";
                $("#divEvent").append(divs);
            }
        }
        else if (periodTime == "2小时") {
            //整个table包含的个5分钟（基本单位）
            var minsCount = timeSpan(dateChoose, '08:00', getDate(dateChoose).DateAdd("d", 1).Format("yyyy-MM-dd").toString(), '00:00');
            var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
            var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (8 * days - 1) + ')').offset().left + tdWidth;
            //整个tabled的宽度
            var tableWid = lasttd - firsttd;
            //div开始的像素点 eveSt
            var dSub = parseInt((getDate(bssd) - getDate(dateChoose)) / 86400000);
            var eveSt = (timeSpan(dateChoose, '08:00', bssd, bsst) - dSub * 8 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
            //div结束的像素点 eveEd
            var eveEd = (timeSpan(dateChoose, '08:00', bsed, bset) - dSub * 8 * 60) / 5 * (tableWid / minsCount) + firsttd + dSub;
            //var lastDay = (new Date(parseFloat( Date.parse(dateChoose) + 1000 * 60 * 60 * 24 * days ))).Format("yyyy-MM-dd");
            wid = eveEd - eveSt;
            var divs = "<div border=1 class='evedivs' id='" + ids + "' name='evedivs' title='" + eve.BookingSchedul[0].undefine2 + "'>"
                 + eve.meetingTheme + "<br/>" + eve.bookingPerson + "</div>";
            $("#divEvent").append(divs);
        }
        else if (periodTime == "10分钟") {
            if (bssd == dateChoose) {
                //整个table包含的个5分钟（基本单位）
                var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '17:10');
                var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
                var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (55 - 1) + ')').offset().left + tdWidth;
                //整个tabled的宽度
                var tableWid = lasttd - firsttd;
                var eveSt = (timeSpan(dateChoose, '08:00', bssd, bsst)) * (tableWid / minsCount) + firsttd;
                //div结束的像素点 eveEd
                var eveEd = (timeSpan(dateChoose, '08:00', bsed, bset)) * (tableWid / minsCount) + firsttd;
                //var lastDay = (new Date(parseFloat( Date.parse(dateChoose) + 1000 * 60 * 60 * 24 * days ))).Format("yyyy-MM-dd");
                wid = eveEd - eveSt + 1;
                var divs = "<div border=1 id='" + ids + "' class='evedivs' name='evedivs' title='" + eve.bookingType + eve.meetingAbstract + eve.bookingPerson + "'>"
                     + eve.meetingTheme + "<br>" + eve.bookingPerson + "</div>";
                $("#divEvent").append(divs);
            }
        }
        //状态为正在申请，待审批
        if (eve.bookingState == 1) {
            $("#" + ids).css("background-color", "#FBE4BE");//#33CCCC
        }
        //状态为锁定， 完成审批或者自助预定
        if (eve.bookingState == 2) {
            $("#" + ids).css("background-color", "#EFEFF0");
        }
        //管理员锁定一段时间，预留其他作用
        if (eve.bookingState == 3) {
            $("#" + ids).css("background-color", "#FEF9F2");
        }
        //状态为取消，解除预定
        if (eve.bookingState == 4) {
            $("#" + ids).remove();
        }
        //状态为审批未通过，类似取消
        if (eve.bookingState == 5) {
            $("#" + ids).remove();
        }
        $("#" + ids).css("z-index", "0");
        $("#" + ids).css("position", "absolute");
        $("#" + ids).css("height", tdHeight + "px");
        $("#" + ids).css("top", evetop + "px");
        $("#" + ids).css("left", eveSt + "px");
        $("#" + ids).css("width", wid + tdWidth + 1 + "px");
    }
}

function creatFreezeDiv(periodTime, ids, mtr) {
    var mName = mtr.mtrId;//取出event所属的会议室名称
    var left = $("#MainTable").offset().left;//maintable相当于窗口的左边的偏移量
    var top = $("#MainTable").offset().top;//maintable元素相对于窗口的上边的偏移量
    var pleft = $("#MainTable").scrollLeft();//maintable元素相对于滚动条左边的偏移量
    var pTop = $("#MainTable").scrollTop();//maintable元素相对于滚动条顶部的偏移量 
    var tdWidth = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').width(); //$('#MainTable').find('tr:eq(' +2+ ')').find('td:eq(' +1+ ')')    //td的宽度
    var tdHeight = $("td[name='" + mtr.mtrId + "']").height() + 2;//td的高度
    //开始的行号
    var trIndex = $("td[name='" + mName + "']").parent().parent().find('tr').index($("td[name='" + mName + "']").parent()[0]);
    var evetop = $("td[name='" + mName + "']").offset().top;
    if (periodTime == "30分钟") {
        //整个table包含的个5分钟（基本单位）
        var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '17:30');
        var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
        var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (19 * days - 1) + ')').offset().left + tdWidth;
        //整个tabled的宽度
        var wid =lasttd - firsttd;
        var eveSt = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
        //wid = eveEd - eveSt;
        var divs = "<div border=1 id='" + ids + "' name='Freezedivs' class = 'Freezedivs' " + ">此场地被冻结，暂不可用,请预定其他场地" + "</div>";
        $("#divEvent").append(divs);
    }
    else if (periodTime == "1小时") {
        if (type != "会议室") {
            //整个table包含的个5分钟（基本单位）
            var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '23:59');
            var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 1 + ')').offset().left;
            var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (16 * days - 1) + ')').offset().left + tdWidth;
            //整个tabled的宽度
            var wid = lasttd - firsttd + tdWidth;
            var eveSt = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
            var divs = "<div border=1 id='" + ids + "' name='Freezedivs'  class = 'Freezedivs'" + ">此场地被冻结，暂不可用,请预定其他场地" + "</div>";
            $("#divEvent").append(divs);
        }
        else if (type == "会议室") {
            var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '18:00');
            var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 1 + ')').offset().left;
            var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (10 * days - 1) + ')').offset().left + tdWidth;
            //整个tabled的宽度
            var wid = lasttd - firsttd + tdWidth;
            var eveSt = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
            var divs = "<div border=1 id='" + ids + "' name='Freezedivs'  class = 'Freezedivs' " + ">此场地被冻结，暂不可用,请预定其他场地" + "</div>";
            $("#divEvent").append(divs);
        }
    }
    else if (periodTime == "2小时") {
        //整个table包含的个5分钟（基本单位）
        var minsCount = timeSpan(dateChoose, '08:00', getDate(dateChoose).DateAdd("d", 1).Format("yyyy-MM-dd").toString(), '00:00');
        var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 1 + ')').offset().left;
        var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (8 * days - 1) + ')').offset().left + tdWidth;
        //整个tabled的宽度
        var wid = lasttd - firsttd + tdWidth;
        var eveSt = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
        var divs = "<div border=1 id='" + ids + "' name='Freezedivs' class = 'Freezedivs' " + ">此场地被冻结，暂不可用,请预定其他场地" + "</div>";
        $("#divEvent").append(divs);
    }
    else if (periodTime == "10分钟") {
        //if (bssd == dateChoose) {
        //整个table包含的个5分钟（基本单位）
        var minsCount = timeSpan(dateChoose, '08:00', dateChoose, '17:10');
        var firsttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
        var lasttd = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + (55 - 1) + ')').offset().left + tdWidth;
        //整个tabled的宽度
        var wid = lasttd - firsttd;
        var eveSt = $('#MainTable').find('tr:eq(' + 2 + ')').find('th:eq(' + 0 + ')').offset().left;
        var divs = "<div border=1 id='" + ids + "' name='Freezedivs'  class = 'Freezedivs' " + ">此场地被冻结，暂不可用,请预定其他场地" + "</div>";
        $("#divEvent").append(divs);
        //}
    }
    $("#" + ids).css("z-index", "1");
    $("#" + ids).css("position", "absolute");
    $("#" + ids).css("height", tdHeight + "px");
    $("#" + ids).css("top", evetop + "px");
    $("#" + ids).css("left", eveSt + "px");
    $("#" + ids).css("width", wid + "px");
    $("#" + ids).css("background-color", "#FEF9F2");
}

//参数定义lt 小日期 yyyy-MM-dd    lt小时间  hh:mm
//参数定义bt 大时间 yyyy-MM-dd    bt大时间  hh:mm
//参数定义 mins 时间差的分钟值
function timeSpan(ld,lt,bd,bt)
{
    var st1 = (ld + " " + lt).replace("-", "/").replace("-", "/");
    var st = parseInt(new Date(st1).getTime() / 1000 / 60);
    var et1 = (bd + " " + bt).replace("-", "/").replace("-", "/");
    var et = parseInt(new Date(et1).getTime() / 1000 / 60);
    return mins = et - st;
}

function cleanAll() {
    $("#tags").html("");
    $("#meetingTheme").val("");
    $("#mtrAdd").attr("value", "");
    $("#specialRequestFirst").attr("value", "");
    $("#specialRequestSecond").attr("value", "");
    $("#meetingAbstract").html("");
}

function checkEndTime(csd, cst) {

    var start = new Date(csd+':'+cst);
    var endTime = $("#endTime").val();
    var end = new Date();
    if (end < start) {
        return false;
    }
    return true;
}